<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="num">
    <button id="btn">添加</button>
    <div id="box"></div>
    <script>
        var arr = [10, 15, 20, 25, 30, 40, 50]
        box.innerHTML = arr;
        /* 有一个从小到大排好序的数组。现输入一个数，要求按原来的规律将它插入数组中。*/ 
        btn.onclick = function (n) {
            // var arr = [10, 15, 20, 25, 30, 40, 50];//编写一组从小到大排好序的数组
            var num = document.getElementById('num').value - 0;  //获取输入的值
            var box = document.getElementById('box');           //获取box
            arr = arr.concat(num);                      //添加num到数组arr
            arr.sort(function (a, b) {
                return a - b;
            });
            box.innerHTML = arr;
            console.log(arr);
        }
        
    </script>
</body>

</html>